package com.yunshang.shoppingmall.service.impl;

import com.alibaba.fastjson.JSON;
import com.yunshang.shoppingmall.entity.SearchHistory;
import com.yunshang.shoppingmall.mapper.SearchHistoryMapper;
import com.yunshang.shoppingmall.service.SearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("searchHistoryService")
public class SearchHistoryServiceImpl implements SearchHistoryService {

    @Autowired
    SearchHistoryMapper searchHistoryMapper;


//    @Autowired
//    RedisTemplate redisTemplate;
//
//    @Autowired
//    StringRedisTemplate stringRedisTemplate;


    @Override
    public int deleteByPrimaryKey(Integer shId) {
        return 0;
    }

    @Override
    public int insert(SearchHistory searchHistory) {
        return searchHistoryMapper.insert(searchHistory);
    }

    @Override
    public int insertSelective(SearchHistory record) {
        return 0;
    }

    @Override
    public SearchHistory selectByPrimaryKey(Integer shId) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(SearchHistory record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(SearchHistory record) {
        return 0;
    }

    /**
     *查询缓存
     * @param userId
     * @return
     */
    @Cacheable(cacheNames = "searchHistoryList")
    @Override
    public List<SearchHistory> selectSearchHistoryByUserId(int userId) {
        List<SearchHistory> searchHistoryList =searchHistoryMapper.selectSearchHistoryByUserId(userId);
//        redisTemplate.opsForList().leftPush("searchHistoryList", JSON.toJSONString(searchHistoryList));
        //redisTemplate.opsForList().leftPush("searchHistoryList", searchHistoryList);
        return searchHistoryList;
    }

    @Override
    public int deleteSearchHistoryByUserId(int userId) {
        return searchHistoryMapper.deleteSearchHistoryByUserId(userId);
    }


}
